<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="https://s3.pstatp.com/cdn/expire-1-M/jquery/3.3.1/jquery.min.js"></script>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css"
          integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

    <!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap-theme.min.css"
          integrity="sha384-6pzBo3FDv/PJ8r2KRkGHifhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ" crossorigin="anonymous">

    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"
            integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
            crossorigin="anonymous"></script>

    <style>
        .requiredSpan {
            color: red;
        }
    </style>
</head>
<body>
<div class="panel panel-default" style="width: 25%; margin: 5% auto;">
    <div class="panel-body">
        <form class="form-horizontal">

            <div class="form-group">
                <label for="commodityType" class="col-sm-2 control-label">水果类型:</label>
                <div class="col-sm-8">
                    <select class="form-control" id="commodityType" class="col-sm-4" required>
                        <option disabled selected>请选择水果类型</option>
                    </select>
                </div>
                <span class="col-sm-2 requiredSpan" id="commodityTypeSpan"></span>
            </div>

            <div class="form-group">
                <label for="commodityType" class="col-sm-2 control-label">水果:</label>
                <div class="col-sm-8">
                    <select class="form-control" id="commodityType" class="col-sm-4" required>
                        <option disabled selected>请选择水果</option>
                    </select>
                </div>
                <span class="col-sm-2 requiredSpan" id="commodityTypeSpan"></span>
            </div>






            <div class="form-group">
                <label for="commodityDescription" class="col-sm-2 control-label">商品说明</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" id="commodityDescription" placeholder="请输入商品说明"
                           required>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-4 col-sm-6">
                    <button type="submit" class="btn btn-primary">保存</button>
                    <button type="button" class="btn btn-danger" style="margin-left: 10px">取消</button>
                </div>
            </div>
        </form>

        <button id="getInfoButton">提交</button>
    </div>


    <script>
        function selectType() {
            $.ajax({
                url: "http://localhost:80/Type/selectType",
                dataType: "json",
                type: "post",
                success: function (resp) {
                    console.log('Response received:', resp);
                    for (let i = 0; i < resp.type.length; i++) {
                        let type = resp.type[i];
                        console.log('Adding option:', type.type);
                        $("<option></option>").val(type.tid).html(type.type).appendTo("#commodityType");
                    }
                },
                error: function (xhr, type, errorThrown) {
                    console.log('XMLHttpRequest对象:', xhr);
                    console.log('错误类型:', type);
                    console.log('错误描述:', errorThrown);
                    alert("请求失败")
                }
            })
        }
    </script>
</div>
</body>
</html>